<?php

namespace app\modules\admin;

use app\models\WxOpenApp;
use app\models\WxOpenWebAppUser;
use Yii;
use yii\web\Controller;
use yii\filters\VerbFilter;
use app\models\User;
use app\models\WxOpenWebApp;

class AdminController extends Controller
{
    public $layout = 'admin';

    //统一报错AJAX
    protected function errorAjax(\Exception $e){
        return json_encode(['errcode'=>$e->getCode(),'errmsg'=>$e->getMessage().$e->getFile().$e->getLine()],JSON_UNESCAPED_UNICODE);
    }
    //统一成功JAX
    protected function successAjax($arr = []){
        return json_encode(array_merge(['errcode'=>0,'errmsg'=>'','result'=>$arr]),JSON_UNESCAPED_UNICODE);
    }
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
        ];
    }

    public function beforeAction($action)
    {
        if (Yii::$app->user->isGuest) {
            $this->redirect('/site/login');
        }
        if (Yii::$app->user->id !=1) {
            $this->redirect('/site/');
        }
        return true;
    }

}
